import SwiftUI

enum Tab: CaseIterable {
    case food
    case store

    var text: String {
        switch self {
        case .food:
            return "美食"
        case .store:
            return "商城"
        }
    }

    var selectedIcon: ImageResource {
        switch self {
        case .food:
            return .iconFoodSelect
        case .store:
            return .iconShopSelect
        }
    }
    
    var unselectedIcon: ImageResource {
        switch self {
        case .food:
            return .iconFoodToolUnselect
        case .store:
            return .iconShopUnselect
        }
    }
}

struct BaseTabbarView: View {
    
    @Binding var currentSelected: Tab
    
    var body: some View {
        VStack(spacing: 0) {
            Color.fs000000.opacity(0.05)
                .frame(height: 1.0, alignment: .top)
            HStack{
                ForEach(Tab.allCases, id: \.self) { tabItem in
                    Button{
                        currentSelected = tabItem
                    } label:{
                        VStack{
                            Image(currentSelected == tabItem ? tabItem.selectedIcon : tabItem.unselectedIcon)
                            Text(tabItem.text)
                        }
                        .foregroundColor(currentSelected == tabItem ? .fs020000 : .fs575958)
                        .frame(maxWidth: .infinity)
                    }
                }
            }
            .padding(.vertical, 6.0)
        }
        .background(Color.fsFFFFFF)
    }
}

#Preview {
    BaseTabbarView(currentSelected: .constant(.food))
}
